package hot;

public class Num34 {
    public int[] searchRange(int[] nums, int target) {
        if(nums.length == 0) return new int[]{-1,-1};
        int i = 0,j = nums.length - 1;
        while(i < j) {
            int mid = (i + j) / 2;
            if(nums[mid] >= target) j = mid;
            else i = mid + 1;
        }
        if(nums[j] != target) return new int[]{-1,-1};
        int L = i;
        i = 0;
        j = nums.length - 1;
        while(i < j) {
            int mid = (i + j + 1) / 2;
            if(nums[mid] <= target) i = mid;
            else j = mid - 1;
        }
        return new int[]{L,j};
    }
}
